<?php
GLOBAL $AppUI, $canRead, $canEdit, $project_id;

$df = $AppUI->getPref('SHDATEFORMAT');

require_once(DP_BASE_DIR."/modules/projects/items/projectitems.class.php");
if (!$canRead) {            // lock out users that do not have at least readPermission on this module
    $AppUI->redirect( "m=public&a=access_denied" );
}
//prepare an html table with a head section
?>
<table class="infopanel" width="100%" cellspacing="0" cellpadding="7" border="0">
<tr>
    <td colspan="100%">
	    <? if($canEdit){?>
		    <input type="button" class="button" onclick="go('index.php?m=projects&u=items&a=projectitems_edit&pitem_id=0&pitem_project=<?=$project_id?>')" value="<?php echo $AppUI->_( 'New Line' );?>"/>
	    <?}?>
    </td>
</tr>
</table>
<div style="overflow: auto; height: 200px;">
<table class="list" width="100%" cellspacing="0" cellpadding="2" border="0">
<tbody>
<tr>
    <th nowrap="nowrap">&nbsp;</th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Item name' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'BL/AW No.' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Invoice No' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Currency' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Invoice amount' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'PO No.' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'CO No.' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Contract No.' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Quantity' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Weight' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Volume' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Container' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Package' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Stamp date' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Stamp time' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Customs dec no' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Custom date' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'ETA date' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Delivery date' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Delivery location' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Inspection' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Unloading' );?></th>
    <th nowrap="nowrap"><?php echo $AppUI->_( 'Remarks' );?></th>

</tr>

<?php
// retrieving some dynamic content using an easy database query
// add/show now gradually the einstein quotes
$project_itemsObj = new CMdProject_items();
$q = new DBQuery();
$project_items = $project_itemsObj->loadProjectItemsByProject($project_id);
if (empty($project_items)) {?>
<tr class="second">
<td colspan="100"><?php echo $AppUI->_( 'No item available' );?></td>
</tr>
<?php
}
$i = 0;
foreach ($project_items as $row) {        //parse the array of einstein quotes
    $i++;
	$stampDate = new CDate($row["pitem_stamp_date"]);
	$customDate = new CDate($row["pitem_custom_date"]);
	$etaDate = new CDate($row["pitem_eta_date"]);
	$deliveryDate = new CDate($row["pitem_delivery_date"]);
?>
<tr class="<?=($i % 2 == 0) ? "second" : "first" ?>">
    <td nowrap="nowrap" width="20">
    <?php if ($canEdit) {    // in case of writePermission on the module show an icon providing edit functionality for the given quote item
        // use the dPFrameWork to show the image
        // always use this way via the framework instead of hard code for the advantage
        // of central improvement of code in case of bugs etc. and for other reasons
        echo "
".'<a href="?m=projects&u=items&a=projectitems_edit&pitem_id='.$row["pitem_id"].'&pitem_project='.$row["pitem_project"]. '">';
        echo dPshowImage( 'images/edit.gif');
        echo "</a>";
    }
    ?>
    </td>
    <td nowrap="nowrap"><?php echo $row["item_name"];?></td>
    <td><?=$row["pitem_BL_AW"];?></td>
    <td><?=$row["pitem_invoice_no"];?></td>
    <td><?=$row["currency_abbreviation"];?></td>
    <td><?=number_format($row["pitem_invoice_amount"]);?></td>
    <td><?=$row["pitem_PO_no"];?></td>
    <td><?=$row["pitem_CO_no"];?></td>
    <td><?=$row["pitem_contract_no"];?></td>
    <td nowrap="nowrap"><?=$row["pitem_quantity"] . ' ' . $row["quantity_name"];?></td>
    <td nowrap="nowrap"><?=$row["pitem_weight"] . ' ' . $row["weight_name"];?></td>
    <td nowrap="nowrap"><?=$row["pitem_volume"] . ' ' . $row["volume_name"];?></td>
    <td><?=$row["pitem_container_total"]. " (" . $row["container_name"] . ")"?></td>
    <td><?=$row["pitem_package"];?></td>
    <td><?=$stampDate->format($df);?></td>
    <td><?=$row["pitem_stamp_time"];?></td>
    <td><?=$row["pitem_customs_dec_no"];?></td>
    <td><?=$customDate->format($df);?></td>
    <td><?=$etaDate->format($df);?></td>
    <td><?=$deliveryDate->format($df);?></td>
    <td><?=$row["pitem_delivery_location"];?></td>
    <td align="center"><?=$row["pitem_inspection"] ? showIconLink('images/tick.gif', '') : '';?></td>
    <td align="center"><?=$row["pitem_unloading"] ? showIconLink('images/tick.gif', '') : '';?></td>
    <td><?=$row["pitem_remarks"];?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>